package com.db.compare;

import com.db.compare.mapper.RbacMenuMapper;
import com.db.compare.model.DbCompareReport;
import com.db.compare.model.RbacMenu;
import com.db.compare.model.RbacUser;
import com.db.compare.service.DbCompareReportService;
import com.db.compare.service.impl.Appcontext;
import com.db.compare.vo.DbCompareReportVo;
import com.db.compare.vo.RbacMenuVo;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@MapperScan(basePackages = "com.db.compare.mapper")
@SpringBootApplication
@Controller
public class YyyyDemoApplication {
    @Autowired
    private DbCompareReportService dbCompareReportService;
    @Autowired
    private RbacMenuMapper rbacMenuMapper;

    public static void main(String[] args) {
        SpringApplication.run(YyyyDemoApplication.class, args);
    }

    @PreAuthorize("hasAuthority('index')")
    @RequestMapping("/index")
    public String defaultPage(Model model){
        DbCompareReportVo dbCompareReportVo = new DbCompareReportVo();
        List<DbCompareReport> dbCompareReportList = dbCompareReportService.findList(dbCompareReportVo);
        RbacMenuVo rbacMenuVo = new RbacMenuVo();
        rbacMenuVo.setStopStatus("0");
        RbacUser rbacUser = Appcontext.getCurrentUser();
        model.addAttribute("rbacUser",rbacUser);
        List<RbacMenu> rbacMenuList = rbacMenuMapper.findList(rbacMenuVo);
        model.addAttribute("rbacMenuList",rbacMenuList);
        model.addAttribute("dbCompareReportList",dbCompareReportList);
        model.addAttribute("count",dbCompareReportList.size());
        return "/html/index";
    }
}
